define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var episode_chapter_id = Config.episode_chapter_id;
    var episode_script_id = Config.episode_script_id;
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'episode/info/index/episode_chapter_id/'+episode_chapter_id+'/episode_script_id/'+episode_script_id+'/' + location.search,
                    add_url: 'episode/info/add/episode_chapter_id/'+episode_chapter_id+'/episode_script_id/'+episode_script_id,
                    edit_url: 'episode/info/edit/episode_chapter_id/'+episode_chapter_id+'/episode_script_id/'+episode_script_id,
                    del_url: 'episode/info/del',
                    multi_url: 'episode/info/multi',
                    import_url: 'episode/info/import',
                    table: 'episode_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cardiac_value', title: __('Cardiac_value')},
                        {field: 'money', title: __('Money')},
                        {field: 'dao_num', title: __('Dao_num')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'thumbnail', title: __('Thumbnail'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'file', title: __('File'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'media_id', title:"媒资文件ID"},
                        {field: 'x_value', title: __('X_value')},
                        {field: 'y_value', title: __('Y_value')},
                        {field: 'episode_producer_num', title: __('Episode_producer_num')},
                        {field: 'cardiac_qualify_value', title: __('Cardiac_qualify_value')},
                        // {field: 'mental_activity', title: __('Mental_activity'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5'),"6":__('Type 6'),"7":__('Type 7')}, formatter: Table.api.formatter.normal},
                        {field: 'version_type', title: __('Version_type'), searchList: {"1":__('Version_type 1'),"2":__('Version_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'is_banner', title: __('Is_banner'), searchList: {"1":__('Is_banner 1'),"2":__('Is_banner 2')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'script.name', title: __('Script.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'chapter.name', title: __('Chapter.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'character.name', title: __('Character.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'level.name', title: __('Level.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'prop.name', title: __('Prop.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $('#c-file').change(function(){
                $("#video-file").prop("src", $('#c-file').val());
                $("#video-file")[0].addEventListener("loadedmetadata", function() {
                    var time = this.duration; 
                    $('#c-file_num').val(time);
                });
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $('#c-file').change(function(){
                $("#video-file").prop("src", $('#c-file').val());
                $("#video-file")[0].addEventListener("loadedmetadata", function() {
                    var time = this.duration; 
                    $('#c-file_num').val(time);
                });
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
				$(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
					//绑定动态下拉组件
					Form.events.selectpage(obj);
				});
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
